package com.qf.application;

import com.qf.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class SearchInit implements CommandLineRunner {

    @Autowired
    private ISearchService searchService;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("启动SpringBoot时触发....");

        //判断索引是否存在，如果索引不存在，就创建索引
        if (!searchService.isIndex()){
            searchService.createIndex();
            searchService.addMappings();
            System.out.println("创建索引并且构建映射类型....");
        }
    }
}
